<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片切换</title>
    <style>
        /* * {
            padding: 0;
            margin: 0;
        } */

        body {
            /* background-color: #FFD8D9; */
            background-image: url(images/1.jpg);
            /* 用url来获取图片链接*/
            background-repeat: no-repeat;
            /* 不重复*/
            background-size: 100% 100%;
            background-attachment: fixed;

        }

        div {
            /* border-color: 1px solid red;
            width: 816px;
            height: 204px; */
            /* margin: 0 auto; */
            padding: 8px 0 0 475px;
            text-align: center;
        }

        img{
            height:100px;
            width :50 px;
        }
        ul {
            list-style-type: none;
        }

        li {
            float: left;
        }
    </style>
</head>


<body>
    <div>
        <ul>
            <li><img src=images/1.jpg></li>
            <li><img src=images/2.jpg></li>
            <li><img src=images/3.jpg></li>
            <li><img src=images/4.jpg></li>
        </ul>
    </div>
    <script>
        let img = document.querySelector('ul').querySelectorAll('img')
        for (let i = 0; i < img.length; i++) {
            img[i].onclick = function () {
                document.body.style.backgroundImage = 'url(' + this.src + ')';
            }
        }
    </script>
</body>

</html>